﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System_Console_Plug
{
    public class Main : CILtoNative.CodePlug
    {
        public void SetupListeners(CILtoNative.PlugBridge bridge)
        {
            bridge.AddPlug("System.Void System.Console::Write(System.String)", CILtoNative.PluggerWrapper.MakeWrapper(1, this));
            bridge.AddPlug("System.Void System.Console::WriteLine(System.Int32)", CILtoNative.PluggerWrapper.MakeWrapper(1, this));
            bridge.AddPlug("System.Void System.Console::WriteLine(System.String)", CILtoNative.PluggerWrapper.MakeWrapper(1, this));
            bridge.AddPlug("System.Void System.Console::set_Title(System.String)", CILtoNative.PluggerWrapper.MakeWrapper(1, this));
            bridge.AddPlug("System.ConsoleKeyInfo System.Console::ReadKey()", CILtoNative.PluggerWrapper.MakeWrapper(0, this));
        }

        public string PlugCode(string Code, List<object> Args)
        {
            if (Code.StartsWith("System.Void System.Console::WriteLine(System.String)"))
            {
                return "System::Console::WriteLine(\"" + Args[0] + "\");";
            }
            else if (Code.StartsWith("System.Void System.Console::set_Title(System.String)"))
            {
                return "System::Console::Title(\"" + Args[0] + "\");";
            }
            else if (Code.StartsWith("System.ConsoleKeyInfo System.Console::ReadKey()"))
            {
                return "System::Console::ReadKey();";
            }
            else if (Code.StartsWith("System.Void System.Console::Write(System.String)"))
            {
                return "System::Console::Write(\"" + Args[0] + "\");";
            }
            else if (Code.StartsWith("System.Void System.Console::WriteLine(System.Int32)"))
            {
                return "System::Console::WriteLine(" + Args[0] + ");";
            }
            return string.Empty;
        }
    }
}
